package kmi.square.wallpaper;

import kmi.droid.animatron.ParticleManager;
import kmi.droid.animatron.Vector2;
import kmi.droid.livewallpaper.cv.CanvasPaintingThread;
import kmi.droid.particles.sample.SimpleParticleSystem;
import kmi.droid.particles.sample.SquareParticleSystem;
import android.content.Context;
import android.graphics.Canvas;
import android.view.MotionEvent;
import android.view.SurfaceHolder;

public class KmiSquareWallpaperPainting extends CanvasPaintingThread
{
	private Vector2 touchPoint = new Vector2(100, 100);
	private long lastUpdateTime = 0;
	private long delta;
	private long timeStep = 10;

	KmiSquareWallpaperPainting(SurfaceHolder surfaceHolder, Context context)
	{
		super(surfaceHolder, context);

		ParticleManager.add(new SimpleParticleSystem(this));
		ParticleManager.add(new SquareParticleSystem(this));
	}

	@Override
	protected void doDraw(Canvas canvas)
	{
		canvas.drawColor(0xFFAEA000);

		ParticleManager.draw(canvas);
	}

	@Override
	protected void updatePhysics()
	{
		long deltaA = getCurrentTime() - lastUpdateTime;
		if (deltaA > timeStep)
		{
			delta = deltaA;
			lastUpdateTime = getCurrentTime();

			ParticleManager.update(delta);
		}
	}

	@Override
	public void doTouchEvent(MotionEvent event)
	{
		setTouchPoint(new Vector2(event.getRawX(), event.getRawY()));

		super.doTouchEvent(event);
	}

	public Vector2 getTouchPoint()
	{
		return touchPoint;
	}

	public void setTouchPoint(Vector2 touchPoint)
	{
		this.touchPoint = touchPoint;
	}
}